function foo(...args) {
  const target = (...argls) => foo(...[...args, ...argls]);
  target.getValue = () => args.reduce((p, n) => p + n, 0);
  return target;
}

var f1 = foo(1, 2, 3);
console.log(f1.getValue()); //6
var f2 = foo(1)(2, 3);
console.log(f2.getValue()); //6
var f3 = foo(1)(2)(3)(4)(5);
console.log(f3.getValue()); //10


function test(...args){
  const target=(...argls)=>test(...[...args,...argls])
  target.getValue=()=>args.reduce((p,n)=>p+n,0)
  return target
}
var f6 = test(1)(2)(3)(4)(5);
console.log(f6.getValue()); //10


function getOuter(){
  var count = 0
  function getCount(num){
  count += num
  console.log(count) //访问外部的date
  }
  return getCount //外部函数返回
 }
 var myfunc = getOuter()
 myfunc(1) // 1
 myfunc(2) // 3